package com.woniuxy.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.InsuranceRecordMapper;
import com.woniuxy.pojo.InsuranceRecord;
import com.woniuxy.service.InsuranceRecordService;
import com.woniuxy.util.DataGridView;
import com.woniuxy.vo.InsuranceRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class InsuranceRecordServiceImpl implements InsuranceRecordService {
    @Autowired
    InsuranceRecordMapper insuranceRecordMapper;

    @Override
    public DataGridView findByPage(InsuranceRecordVo insuranceRecordVo) {
        Page<Object> page= PageHelper.startPage(insuranceRecordVo.getPage(),insuranceRecordVo.getLimit());
        List<InsuranceRecord> list=insuranceRecordMapper.selectByCondition(insuranceRecordVo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public boolean add(InsuranceRecord insuranceRecord) {
        int res = insuranceRecordMapper.insert(insuranceRecord);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean update(InsuranceRecord insuranceRecord) {
        int res = insuranceRecordMapper.update(insuranceRecord);
        if(res>0){
            return true;
        }
        return false;
    }

    @Override
    public boolean removeById(int id) {
        insuranceRecordMapper.deleteById(id);
        return true;
    }

    @Transactional
    @Override
    public void removeBatch(Integer[] ids) {
        if(ids.length>0){
            for(Integer id:ids){
                this.removeById(id);
            }
        }
    }
}
